package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.constant.OrderStatusConstants;
import cn.itsource.ymcc.domain.CourseOrder;
import cn.itsource.ymcc.result.JsonResult;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
@RocketMQMessageListener(
        consumerGroup = "OrderConsumer",
        topic = OrderStatusConstants.TOPIC_COURSE_ORDER_PUSH_TO_SRS,
        selectorExpression = OrderStatusConstants.TAGS_COURSE_ORDER_PUSH_TO_SRS
)
@Slf4j
public class OrderConsumer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            byte[] body = messageExt.getBody();
            String s = new String(body, "utf-8");
            CourseOrder courseOrder = JSONObject.parseObject(s, CourseOrder.class);

            //需要注意的是给谁发
            System.out.println("你的订单:"+courseOrder.getOrderNo()+"下单成功！");

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
